import cn.xnatural.enet.common.Log
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.alibaba.fastjson.parser.Feature

//Log.init(null)
//@groovy.transform.Field Log log = Log.of(getClass().simpleName)
//log.info 'xxxxxxxxxxxxx'
//return

// 平级json所有key
JSON.parse(new File("E:\\company\\锦程消息金融/1.txt").getText(), JSON.DEFAULT_PARSER_FEATURE | Feature.OrderedField.mask).each { e ->
    if (e.value instanceof JSONObject) eachJo(e.key, e.value)
    else if (e.value instanceof List) eachList(e.key, e.value)
    else println e.key
}

// 转换成一级map
// def m = new LinkedHashMap()


def eachJo(key, jo) {
    jo.each{e ->
        if (e.value instanceof JSONObject) eachJo(key + "." + e.key, e.value)
        else if (e.value instanceof List) eachList(key + "." + e.key, e.value)
        else println key + "." + e.key
    }
}


def eachList(key, ja) {
    ja.each{e ->
        if (e instanceof JSONObject) eachJo(key + "[]", e)
        else if (e instanceof List) eachList(key + "[]", e)
        else println key + "[]"
    }
}